<?php

namespace app\api\controller;

use app\JjjController;
use think\facade\Db;

class Datanexus extends Controller
{

    public function initialize()
    {

    }

    /**
     * https://datanexus.qq.com/doc/develop/guider/interface/conversion/trackingcgi_api_web
     * 回调
     */
    public function callback()
    {
        // {
        //     "click_id": "wxadclicke5hnzpddzovfg",
        //     "click_time": "1763022436",
        //     "account_id": "55994695",
        //     "cb": "https:\/\/api.e.qq.com\/v3.0\/user_actions\/add?cb=k5L0fwwlOmfOrG2uqwlneWJ2k0SXv3ddVEnP1FrVf-CPqxE9Az48FGlSCo7AMdjg&conv_id=68809229"
        // }
        $params = $this->request->param();
        Db::table('jjjshop_datanexus')->insert([
            'params'=> json_encode($params),
            'create_time' => time(),
        ]);
        return $this->renderSuccess();
    }

    public function log()
    {
        $type = $this->request->post('type','');
        $client_id = $this->request->post('client_id','');
        if (!empty($client_id)) {
            $type_list = array_keys(\TengxunAD::action_type_list);
            if (!in_array($type, $type_list)) {
                return $this->renderError('类型错误');
            }
            $user = $this->getUser();
            $res = (new \TengxunAD())->add($user['open_id'],$type,$client_id);
        }
        return $this->renderSuccess();
    }
}